home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / ulog / Ulog_ClearLogins.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-13  |  2.6 KB  |  112 lines

  1. /* 
  2.  * Ulog_ClearLogins.c --
  3.  *
  4.  *    Source code for the Ulog_ClearLogins procedure.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/lib/c/ulog/RCS/Ulog_ClearLogins.c,v 1.2 89/01/13 11:49:52 douglis Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20.  
  21. #include <ulog.h>
  22. #include "ulogInt.h"
  23.  
  24.  
  25. /*
  26.  *----------------------------------------------------------------------
  27.  *
  28.  * Ulog_ClearLogins --
  29.  *
  30.  *    Void any user log records for the current host.
  31.  *
  32.  * Results:
  33.  *    0 on success, -1 if an error occurs (and errno will indicate the
  34.  *    nature of the error).
  35.  *
  36.  * Side effects:
  37.  *    The 'user log' is opened and locked while it is being modified.
  38.  *
  39.  *----------------------------------------------------------------------
  40.  */
  41.  
  42.  
  43. int
  44. Ulog_ClearLogins()
  45. {
  46.     char myHostName[ULOG_LOC_LENGTH];
  47.     char buffer[ULOG_RECORD_LENGTH];
  48.     Host_Entry *hostPtr;
  49.     Db_Handle handle;
  50.     int errnoTmp;
  51.     int i;
  52.  
  53.     if (gethostname(myHostName, ULOG_LOC_LENGTH) < 0) {
  54.     syslog(LOG_ERR, "Ulog_ClearLogins: error in gethostname.\n");
  55.     return(-1);
  56.     }
  57.     hostPtr = Host_ByName(myHostName);
  58.     Host_End();
  59.     if (hostPtr == (Host_Entry *) NULL) {
  60.     syslog(LOG_ERR,
  61.            "Ulog_ClearLogins: error in Host_ByName for current host.\n");
  62.     return(-1);
  63.     }
  64.  
  65.     if (Db_Open(ULOG_FILE_NAME, ULOG_RECORD_LENGTH, &handle, 1,
  66.              DB_LOCK_OPEN, DB_LOCK_BREAK, 0) < 0) {
  67.     return(-1);
  68.     }
  69.  
  70.     bzero(buffer, ULOG_RECORD_LENGTH);
  71.     (void) sprintf(buffer, ULOG_FORMAT_STRING, -1, hostPtr->id, -1,
  72.          0, "(none)");
  73.  
  74.     /*
  75.      * Write the first entry, specifying the location.  Then do writes
  76.      * sequentially (avoiding seeks).
  77.      */
  78.  
  79.     if (Db_Put(&handle, buffer, hostPtr->id * ULOG_MAX_PORTS) < 0) {
  80.     goto error;
  81.     }
  82.     
  83.     for (i = 1; i < ULOG_MAX_PORTS; i++) {
  84.     if (Db_Put(&handle, buffer, -1) < 0) {
  85.         goto error;
  86.     }
  87.     }
  88.     if (Db_Close(&handle) < 0) {
  89.     return(-1);
  90.     }
  91.     return(0);
  92.  
  93.  
  94.     /*
  95.      * On error, try to close the database, but make sure to return
  96.      * the error in errno that came from the error that made us quit.
  97.      */
  98. error:
  99.     errnoTmp = errno;
  100.     (void) Db_Close(&handle);
  101.     errno = errnoTmp;
  102.  
  103.     return(-1);
  104. }
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.